<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>块状元素水平垂直居中</title>
    <style>
        body{
            margin: 0;
        }
        .k{
            width: 400px;
            height: 400px;
            border: 1px solid #000;
            position: absolute;
            top: 50%;
            left: 50%;
            margin-top: -200px;
            margin-left: -200px;
        }
    </style>
</head>
<body>
    <div class="k"> </div>
</body>
</html>